package bird.spring.com.designpattern;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;

import bird.spring.com.designpattern.ImageLoader.ImageLoader;
import bird.spring.com.designpattern.RoomDemo.Mediator;
import bird.spring.com.designpattern.RoomDemo.MyMediator;
import bird.spring.com.designpattern.RoomDemo.Tenant;
import bird.spring.com.designpattern.SuperImageLoader.DoubleCache;
import bird.spring.com.designpattern.SuperImageLoader.SuperImageLoader;

public class MainActivity extends AppCompatActivity {
    ImageView image1, image2;
    ImageLoader simpleLoader;
    SuperImageLoader superImageLoader;

    private static final String URL1 = "http://pic61.nipic.com/file/20150301/13101063_113525995825_2.jpg";
    private static final String URL2 = "http://img5.duitang.com/uploads/item/201407/03/20140703235935_RxS2M.jpeg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        InitView();


        RentRoom();
        newRentRoom();

    }

    private void newRentRoom() {
        Tenant tenant=new Tenant();
        MyMediator myMediator=new MyMediator();
        tenant.myRentRoom(myMediator);
    }

    private void RentRoom() {
        Tenant tenant = new Tenant();
        Mediator mediator = new Mediator();
        System.out.println("----------> " + mediator.getAllRooms().toString());
        tenant.rentRoom(mediator);


    }

    private void InitView() {
        image1 = (ImageView) findViewById(R.id.imageView);
        image2 = (ImageView) findViewById(R.id.imageView2);
        simpleLoader = new ImageLoader();
        simpleLoader.displayImage(URL1, image1);


        superImageLoader = new SuperImageLoader();
        DoubleCache doubleCache = new DoubleCache();
        superImageLoader.setImageCache(doubleCache);
        superImageLoader.displayImage(URL2, image2);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
